/**
 *
 */
/**
 *
 */
//选择状态
function getType(type){
	switch(type){
	case 1:return "使用中";
	case 2:return "未使用";
	case 3:return "禁用";
	case 4:return "无法使用";
	default:return "";
	}
}
//选择class
function SelectClass(type){
	switch(type){
	case 1:return "text-success";
	case 2:return "text-info";
	case 3:return "text-warning";
	case 4:return "text-danger";
	default:return "text-warning";
	}
}
/*选择页码获取分页数据*/
var page = 1;
function SelectPage(pageNo){
	$('#indexBody').append('<td colspan="8"><h2 style="text-align:center">数据加载中。。。</h2></td>')
	page = pageNo;
	$.ajax({
		type:"post",
		url:"book/index.do",
		datatype: "json",
		async:true,
		data:{
			"pageNo":pageNo,
			"queryStr":$('#queryStr').val()==null?"":$('#queryStr').val(),
			"sortStr":$('#sortStr').val()==null?"":$('#sortStr').val()
		},
		success:function(r) {
			/* 渲染数据 */
			var bookdate = r.bookdate;
			var pagination = r.pagination;
			//当前页面
			var PageNo = pagination.pageNo;
			$('#indexBody').html('');
			if(bookdate.length==0){$('#indexBody').html('<td colspan="8"><h2 style="text-align:center">没有数据</h2></td>');}
			$.each(bookdate, function (index, book) {
				$('#indexBody').append(
						'<tr>'
							+'<td><label class="lyear-checkbox checkbox-primary"><input type="checkbox" name="baseTable" value="'+book.id+'"><span></span> </label></td>'
							+'<td style="text-align:center;">'+book.id+'</td>'
							+'<td style="text-align:center;">'+book.title+'</td>'
							+'<td style="text-align:center;">'+book.name+'</td>'
							+'<td style="text-align:center;">'+book.author+'</td>'
							+'<td style="text-align:center;">'+book.readings+'</td>'
							+'<td style="text-align:center;"> <h5 class="'+SelectClass(book.type)+'">'+getType(book.type)+'</h5></td>'
							+'<td style="text-align:center;">'
							+'<div class="btn-group">'
							+'<a class="btn btn-xs btn-default" href="javascript:void();" onclick="Edit('+book.id+','+PageNo+')" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>'
							+'<a class="btn btn-xs btn-default" href="javascript:void();" onclick="Delete('+book.id+','+PageNo+')" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>'
							+'</div>'
							+'</td>'
						+'</tr>'
				);
			});
			/* 渲染页码 */
			RenderPagination(r.pagination);
		},
		error:function(){
			AjaxError();
		}
	});
}
SelectPage(page);